import java.io.StringWriter;
import java.rmi.RemoteException;
import java.text.NumberFormat;
import java.util.Properties;

public class OverviewManager {
	private NumberFormat nf;

	public OverviewManager(NumberFormat nf) {
		this.nf = nf;
	}

	public String updateOverview(WarehouseInterface server, String name, int id)
			throws RemoteException {
		ProductInterface product = null;
		float finalPrice = 0;
		Properties wagentje = server.getOrderOverview(name, id);
		StringWriter writer = new StringWriter();
		writer.append("Winkelmand van " + name + "\n");
		for (Object o : wagentje.keySet()) {
			product = (ProductInterface) o;
			Integer productAmount = (Integer) wagentje.get(o);
			Float totaalPrijs = product.getPrice() * productAmount;
			writer.append(product.getName() + ": \u20AC"
					+ nf.format(product.getPrice()) + " x " + productAmount
					+ "= \u20AC" + nf.format(totaalPrijs) + "\n");
			finalPrice += totaalPrijs;
		}
		if (finalPrice > 0) {
			writer.append("Totaalprijs: \u20AC" + nf.format(finalPrice));
		} else {
			writer.append("<leeg>");
		}
		return writer.toString();
	}
}
